<?php

class Home extends Controller {

	function Home()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$data['message'] = 'Welcome to Login Panel';
		$data['action'] = site_url('admin/processlogin');
		$this->load->view('homepage',$data);
	}
	function signup()
	{
	$data['message'] = 'Fill these textfields and submit it';
	$data['action'] = site_url('home/saveaccount');
	$this->load->view('signup_view',$data);
	}
	function saveaccount()
	{
	$username = $this->input->post('username');
	
	$this->form_validation->set_rules('username', 'Username', 'required');
	$this->form_validation->set_rules('name', 'Name', 'required');
	$this->form_validation->set_rules('studno', 'Student No', 'required');
	$this->form_validation->set_rules('address', 'Address', 'required');
	$this->form_validation->set_rules('age', 'Age', 'required');
	$this->form_validation->set_rules('email', 'Email Address', 'required');
	$this->form_validation->set_rules('password', 'Password', 'required');

			if ($this->form_validation->run() == FALSE)
				{	
					$data['message'] = 'Fill all textbox!';
					$data['action'] = site_url('home/saveaccount');
					$this->load->view('signup_view',$data);
				}
				else
				{
					$this->db->like('username', $username); 
					$query = $this->db->get('user');
					
					if ($query->num_rows() == 0){
						$data = array(
							'username' => $_POST['username'],
							'password' => $_POST['password'],
							'usertype' => 'browser',
							'name' => $_POST['name'],
							'studno' => $_POST['studno'],
							'address' => $_POST['address'],
							'age' => $_POST['age'],
							'email' => $_POST['email'],
						
						);
						$this->db->insert('user', $data);
						//$data['message'] = 'Account saved! Log now.';
						$this->load->view('accountsaved');
					}else
					{
						$data['message'] = 'The Username you entered is not available';
						$data['action'] = site_url('home/saveaccount');
						$this->load->view('signup_view',$data);
					}	
				}
	}
	
}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */